<?php

class simpleUrl {

    var $site_path;

    function __construct($site_path) {
        $this->site_path = $this->removeSlash($site_path);
    }

    function __toString() {
        return $this->site_path;
    }

    private function removeSlash($string) {
        if ($string[strlen($string) - 1] == '/')
            $string = rtrim($string, '/');
        return $string;
    }

    function segment($segment) {
        $caminho = $_SERVER['REQUEST_URI'];

        if (substr($caminho, -1) != '/')
            $caminho = ($caminho . "/");

        $url = str_replace($this->site_path, '', $caminho);
        $url = explode('/', $url);

        if (isset($url[$segment]))
            return $url[$segment];
        else
            return $url;
    }

}

?>
